from openai import OpenAI

def get_local_xinference_client():
    """
    获取xinfer的client
    :return:
    """
    url = "http://127.0.0.1:9997/v1"
    client = OpenAI(
        api_key='EMPTY',
        base_url=url,
    )
    return client
def get_xinference_client():
    """
    获取xinfer的client
    :return:
    """
    url = "http://10.106.153.12:9997/v1"
    client = OpenAI(
        api_key='EMPTY',
        base_url=url,
    )
    return client
def chat_openai(client,messages,model = "qwen1half-32b-chat"):
    completion = client.chat.completions.create(
      model=model,
      messages=messages,  temperature=0.3)
    return completion.choices[0].message.content

if __name__ == '__main__':
    t  = '你是谁'
    res = chat_openai(get_xinference_client(), [{"role": "user", "content": t}], model="qwen1half-7b-chat")
    print(res)